package test.utils;

import com.jayway.jsonpath.JsonPath;
import org.json.JSONArray;
import org.json.JSONObject;
import org.testng.Assert;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;

public class JsonResult {
	
	private String jsonStr = "";
	private String path = "";
	private String resultStr = null;
	private boolean isHaveassertResult = false;
	private boolean assertResult = true;
	private int length = 0;
	private int count = 0;   //mysql的查询结果总数
	
	public static JsonResult parse(String jsonStr) {
		JsonResult jsonPath = new JsonResult();
		jsonPath.setJsonStr(jsonStr);
		jsonPath.resultStr = jsonStr;
		return jsonPath;
	}
	
	public Double toDouble() {
		try {
			return Double.valueOf(this.resultStr);
		} catch (Exception e) {
			return null;
		}
	}
	
	public Integer toInt() {
		if (this.resultStr == null) {
			return null;
		}
		try {
			return Integer.valueOf(this.resultStr);
		} catch (Exception e) {
			return null;
		}
	}
	
	public String toString() {
		if (this.resultStr == null) {
			return null;
		}
		return this.resultStr.toString();
	}
	
	public JSONArray toJsonArray() {
		try {
			return new JSONArray(this.resultStr);
		} catch (Exception e) {
			return null;
		}
	}
	
	public JSONObject toJsonObject() {
		try {
			return new JSONObject(this.resultStr.toString());
		} catch (Exception e) {
			return null;
		}
	}
	
	public boolean toBoolean() {
		try {
			if ("true".equals(this.resultStr) || "1".equals(this.resultStr)) {
				return true;
			}
		} catch (Exception e) {
		}
		return false;
	}
	
	public boolean hasArrayItems() {
		isHaveassertResult = true;
		try {
			if (toJsonArray().length()>0) {
				this.assertResult = true;
				return assertResult;
			}
		} catch (Exception e) {
		}
		this.assertResult = false;
		return assertResult;
	}
	
	public boolean hasKey(String keyName) {
		isHaveassertResult = true;
		try {
			if (toJsonObject() != null) {
				JSONObject object = toJsonObject();
				if (object.has(keyName)) {
					this.assertResult = true;
					return assertResult;
				}
			}else if (toJsonArray() != null) {
				JSONArray array = toJsonArray();
				if (array != null && array.length()>0) {
					for(int i=0;i<array.length();i++) {
						JSONObject object = array.getJSONObject(i);
						if (!object.has(keyName)) {
							break;
						}
					}
					this.assertResult = true;
					return assertResult;
				}
			}
		} catch (Exception e) {
		}
		this.assertResult = false;
		return assertResult;
	}
	
	public boolean contains(String value) { 
		isHaveassertResult = true;
		try {
			if (this.resultStr.contains(value)) {
				this.assertResult = true;
				return assertResult;
			}
		} catch (Exception e) {
		}
		this.assertResult = false;
		return assertResult;
	}
	
	public JsonResult assertEqual(String expect) {
		assertEquals(this.resultStr, expect);
		return this;
	}
	
	public JsonResult assertGreaterEqual(int expect, String message) {
		if (this.length<expect) {
			assertResult  = false;
		}
		return this;
	}
	
	public JsonResult setAssertResult(boolean b) {
		isHaveassertResult = true;
		assertResult = b;
		return this;
	}
	
	public JsonResult assertLessEqual(int expect, String message) {
		if (this.length>expect) {
			setAssertResult(false);
		}
		return this;
	}
	
	public JsonResult assertLess(int expect, String message) {
		if (this.length>=expect) {
			setAssertResult(false);
		}
		return this;
	}
	
	public JsonResult assertGrater(Integer expect, String message) {
		if (this.length<=expect) {
			setAssertResult(false);
		}
		return this;
	}
	
	public JsonResult assertEqual(String expect, String message) {
		if (!expect.equals(this.resultStr)) {
			setAssertResult(false);
		}
		return this;
	}
	
	public JsonResult assertNotEqual(String expect) {
		assertNotEquals(this.resultStr, expect);
		return this;
	}
	
	public JsonResult assertNotEqual(String expect, String message) {
		if (!expect.equals(this.resultStr)) {
			setAssertResult(false);
		}
		return this;
	}
	
	/**
	 * 判断是否是jsonobject，jsonarray，判断key value是否一致
	 * @param key
	 * @param value
	 * @return
	 */
	public JsonResult assertKeyValueEqual(String key, String value) {
		try {
			JSONObject object = toJsonObject();
			assertEquals(object.get(key).toString(), value);
			return this;
		} catch (Exception e) {
		}
		try {
			JSONArray object = toJsonArray();
			for(int i=0;i<object.length();i++) {
				assertEquals(object.getJSONObject(i).get(key).toString(), value);
			}
			return this;
		} catch (Exception e) {
		}
		Assert.assertFalse(true, "不能匹配，因为不是一个有效的jsonobject或jsonarray");
		return this;
	}
	
	/**
	 * 判断是否是jsonobject，jsonarray，判断key value是否一致
	 * @param key
	 * @param value
	 * @return
	 */
	public JsonResult assertKeyValueEqual(String key, String value, String message) {
		try {
			JSONObject object = toJsonObject();
			if (!value.equals(object.get(key).toString())) {
				setAssertResult(false);
			}
			return this;
		} catch (Exception e) {
		}
		try {
			JSONArray object = toJsonArray();
			for(int i=0;i<object.length();i++) {
				if (!value.equals(object.getJSONObject(i).get(key).toString())) {
					setAssertResult(false);
				}
			}
			return this;
		} catch (Exception e) {
		}
		setAssertResult(false);
		return this;
	}
	
	/**
	 * 元素个数比较
	 * @param size
	 * @return
	 */
	public JsonResult assertEqual(int size) {
		assertEquals(this.length, size);
		return this;
	}
	
	/**
	 * 元素个数比较
	 * @param size
	 * @return
	 */
	public JsonResult assertEqual(int size, String message) {
		if (size != this.length) {
			setAssertResult(false);
		}
		assertEquals(this.length, size, message);
		return this;
	}
	
	public JsonResult assertNull() {
		Assert.assertNull(this.resultStr);
		return this;
	}
	
	public JsonResult assertNull(String message) {
		Assert.assertNull(this.resultStr, message);
		return this;
	}
	
	public JsonResult assertNotNull() {
		Assert.assertNotNull(this.resultStr);
		return this;
	}
	
	public JsonResult assertNotNull(String message) {
		Assert.assertNotNull(this.resultStr, message);
		return this;
	}
	
	public JsonResult assertHasArrayItems() {
		hasArrayItems();
		assertTrue();
		return this;
	}
	
	public JsonResult assertHasArrayItems(String message) {
		hasArrayItems();
		assertTrue(message);
		return this;
	}
	
	public JsonResult assertNoArrayItems() {
		return assertNoArrayItems("");
	}
	
	public JsonResult assertNoArrayItems(String message) {
		hasArrayItems();
		if (isHaveassertResult == false) {
			this.assertResult = false;
			return this;
		}
		return this;
	}
	
	public JsonResult assertHasKey(String key) {
		hasKey(key);
		assertTrue();
		return this;
	}
	
	public JsonResult assertHasKey(String key, String message) {
		hasKey(key);
		assertTrue(message);
		return this;
	}

	public JsonResult assertNokey(String key) {
		hasKey(key);
		assertFalse();
		return this;
	}
	
	public JsonResult assertNokey(String key, String message) {
		hasKey(key);
		assertFalse(message);
		return this;
	}
	
	public JsonResult assertContains(String arg) {
		Assert.assertTrue(contains(arg));
		return this;
	}
	
	public JsonResult assertContains(String arg, String message) {
		if (!contains(arg)) {
			setAssertResult(false);
		}
		Assert.assertTrue(contains(arg), message);
		return this;
	}
	
	public JsonResult assertNotContains(String arg) {
		Assert.assertTrue(!contains(arg));
		return this;
	}
	
	public JsonResult assertNotContains(String arg, String message) {
		if (contains(arg)) {
			setAssertResult(false);
		}
		Assert.assertTrue(!contains(arg), message);
		return this;
	}
	
	private JsonResult assertTrue() {
		return assertTrue("");
	}
	
	private JsonResult assertTrue(String message) {
		if (isHaveassertResult == false) {
			this.assertResult = false;
		}
		return this;
	}

	private JsonResult assertFalse() {
		return assertFalse("");
	}
	
	private JsonResult assertFalse(String message) {
		if (isHaveassertResult == true) {
			this.assertResult = true;
			return this;
		}
		return this;
	}
	
	/**
	 * 判断是否降序
	 * @param key
	 * @return
	 */
	public JsonResult assertSortDesc(String key, String message) {
		try {
			JSONArray arr = toJsonArray();
			if (arr.length() > 1) {
				boolean temp= true;
				for (int i = 0; i < arr.length(); i++) {
					if (i < arr.length()-1) {
						if (!arr.getJSONObject(i).has(key) || !arr.getJSONObject(i).has(key)) {
							return this;
						}
						if (arr.getJSONObject(i).get(key) == null || arr.getJSONObject(i).get(key).toString().equals("null") || "".equals(arr.getJSONObject(i).get(key))) {
							break;
						}
						if (arr.getJSONObject(i+1).get(key) == null || arr.getJSONObject(i+1).get(key).toString().equals("null") || "".equals(arr.getJSONObject(i+1).get(key))) {
							break;
						}
						double thisValue = Double.valueOf(arr.getJSONObject(i).get(key).toString());
						double nextvalue = Double.valueOf(arr.getJSONObject(i+1).get(key).toString());
						if (thisValue<nextvalue) {
							temp = false;
						}
					}
				}
				if (!temp) {
					setAssertResult(false);
				}
			}
		} catch (Exception e) {
		}
		return this;
	}
	
	/**
	 * 判断是否升序
	 * @param key
	 * @return
	 */
	public JsonResult assertSortAsc(String key) {
		return assertSortAsc(key, "");
	}
	
	/**
	 * 判断是否降序
	 * @param key
	 * @return
	 */
	public JsonResult assertSortDesc(String key) {
		return assertSortDesc(key, "");
	}
	
	/**
	 * 判断是否升序
	 * @param key
	 * @return
	 */
	public JsonResult assertSortAsc(String key, String message) {
		try {
			JSONArray arr = toJsonArray();
			if (arr.length() > 1) {
				boolean temp = true;
				for (int i = 0; i < arr.length(); i++) {
					if (i < arr.length()-1) {
						if (!arr.getJSONObject(i).has(key) || !arr.getJSONObject(i).has(key)) {
							return this;
						}
						if (arr.getJSONObject(i).get(key) == null || arr.getJSONObject(i).get(key).toString().equals("null") || "".equals(arr.getJSONObject(i).get(key))) {
							break;
						}
						if (arr.getJSONObject(i+1).get(key) == null || arr.getJSONObject(i+1).get(key).toString().equals("null") || "".equals(arr.getJSONObject(i+1).get(key))) {
							break;
						}
						double thisValue = Double.valueOf(arr.getJSONObject(i).get(key).toString());
						double nextvalue = Double.valueOf(arr.getJSONObject(i+1).get(key).toString());
						if (thisValue>nextvalue) {
							temp = false;
							break;
						}
					}
				}
				if (!temp) {
					setAssertResult(false);
				}
			}
		} catch (Exception e) {
		}
		return this;
	}
	
	/**
	 * jsonpath
	 */
	public JsonResult read(String path) {
		this.setPath(path);
		//如果json串为空
		if (this.jsonStr == null || this.jsonStr.equals("")) {
			return this;
		}
		JSONObject object = null;
		//如果json串格式不正确
		try {
			object = new JSONObject(this.jsonStr);
		} catch (Exception e) {
			this.resultStr = null;
			return this;
		}
		//如果path是空，则返回json
		if ("".equals(path) || path == null) {
			this.resultStr = this.jsonStr;
			return this;
		}
		//开始分析path路径
		String [] paths = path.split("\\.");
		try {
			for(int i=0; i<paths.length; i++) {
				//如果最后一个元素以[]为结尾
				if (i == paths.length-1) {
					if (paths[i].endsWith("[]")) {
						this.resultStr = object.getJSONArray(paths[i].replace("[]", "")).toString();
						return this;
					}
				}
				//如果元素中包含[、]
				if (paths[i].contains("[") && paths[i].contains("]")) {
					String [] arg = paths[i].split("\\[");
					int value = 0;
					JSONArray array = object.getJSONArray(arg[0]);
					String ll = paths[i].replace(arg[0], "");
					String temp = ll.substring(1, ll.lastIndexOf("]"));
					String [] args = temp.split("\\]\\[");
					for(int j=0;j<args.length;j++) {
						temp = args[j].replace("]", "").replace("[", "");
						if ("*".equals(temp) || "".equals(temp)) {
							String liString  = "";
							if (i+1 != paths.length-1) {
								return this;
							}
							for(int k=0;k<array.length();k++) {
								if ("".equals(liString)) {
									liString = array.getJSONObject(k).get(paths[i+1]).toString();
								}else {
									liString = liString+","+array.getJSONObject(k).get(paths[i+1]);
								}
							}
							this.resultStr = liString;
							return this;
						}else if (temp.contains("==")) {
							String myString = temp;
								String [] keyvalue = myString.split("==");
								String key = keyvalue[0].trim();
								String myvalue = keyvalue[1].trim();
								for(int k=0; k<array.length(); k++) {
									if (array.getJSONObject(k).get(key).equals(myvalue)) {
										object = array.getJSONObject(k);
										break;
									}
								}
								//如果是最后一个元素，且取数组的值
								if (i == paths.length-1) {
									this.resultStr = object.toString();
									return this;
								}
						}else {
							value = Integer.valueOf(temp);
							//如果取数组值超过最大值
							if (value>=array.length()) {
								this.resultStr = null;
								return this;
							}
							if (j<args.length-1) {
								array = array.getJSONArray(value);
							}else {
								object = array.getJSONObject(value);
							}
						}
					}
					//如果是最后一个元素，且取数组的值
					if (i == paths.length-1) {
						this.resultStr = object.toString();
						return this;
					}
				}else {  //如果不包含[、],只是个普通元素
					if (i == paths.length-1) { //最后一个元素
						this.resultStr = object.get(paths[i]).toString();
						return this;
					}else { //不是最后一个元素
						object = (JSONObject) object.get(paths[i]);
					}
				}
			}
		} catch (Exception e) {
		}
		//如果自定义jsonpath异常，再用JSONPATH第三方组件查找
		try {
			this.resultStr = JsonPath.parse(this.jsonStr).read(path).toString();
			return this;
		} catch (Exception e) {
		}
		this.resultStr = null;
		return this;
	}
	
	public String getResult() {
		return resultStr;
	}

	public JsonResult setResult(String result) {
		this.resultStr = result;
		return this;
	}

	public JsonResult getLength() {
		try {
			if (this.resultStr != null) {
				try {
					if (this.resultStr.endsWith("]")) {
						this.length = new JSONArray(this.resultStr).length();
						return this;
					}else {
						this.length = new JSONObject(this.resultStr).length();
						return this;
					}
				} catch (Exception e) {
					this.length = this.resultStr.length();
					return this;
				}
			}
		} catch (Exception e) {
			this.length = 0;
		}
		return this;
	}
	
	public String getJsonStr() {
		return jsonStr;
	}

	public void setJsonStr(String jsonStr) {
		this.jsonStr = jsonStr;
	}
	
	public boolean retCode() {
		read("retCode");
		if ("1".equals(toString())) {
			return true;
		}
		return false;
	}
	
	public static void main(String[] args) {
		String json = "{\"retCode\":\"1\",\"data\":{\"picture\":[{\"id\":7385,\"catalogId\":\"1\",\"isEnable\":1,\"spuId\":201704,\"description\":\"<p>web1</p>\",\"channelCode\":\"web\",\"sourceType\":3,\"createdBy\":\"Sync\",\"createdTime\":1531375431000,\"modifiedBy\":null,\"modifiedTime\":null,\"field1\":null,\"field2\":null,\"field3\":null,\"field4\":null,\"descTitle\":\"投保须知\",\"descSort\":null,\"salesArea\":null,\"createdTimeStr\":\"2018-07-12\",\"modifiedTimeStr\":\"\"},{\"id\":7386,\"catalogId\":\"1\",\"isEnable\":1,\"spuId\":201704,\"description\":\"<p>web2</p>\",\"channelCode\":\"web\",\"sourceType\":3,\"createdBy\":\"Sync\",\"createdTime\":1531375431000,\"modifiedBy\":null,\"modifiedTime\":null,\"field1\":null,\"field2\":null,\"field3\":null,\"field4\":null,\"descTitle\":\"免责声明\",\"descSort\":null,\"salesArea\":null,\"createdTimeStr\":\"2018-07-12\",\"modifiedTimeStr\":\"\"},{\"id\":7387,\"catalogId\":\"1\",\"isEnable\":1,\"spuId\":201704,\"description\":\"<p>[{\\\"LPZY\\\":\\\"\\\",\\\"plan\\\":\\\"{\\\\\\\"guide\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"begin_sale_date\\\\\\\":\\\\\\\"20180516\\\\\\\",\\\\\\\"insure_day\\\\\\\":\\\\\\\"12\\\\\\\",\\\\\\\"company_id\\\\\\\":11,\\\\\\\"product_id\\\\\\\":333,\\\\\\\"state\\\\\\\":\\\\\\\"0\\\\\\\",\\\\\\\"insert_time\\\\\\\":1528533314000,\\\\\\\"sale_count\\\\\\\":0,\\\\\\\"category_id\\\\\\\":\\\\\\\"14\\\\\\\",\\\\\\\"premium_amt\\\\\\\":100.0,\\\\\\\"insure_amt\\\\\\\":655000.0,\\\\\\\"plan_code\\\\\\\":\\\\\\\"151201\\\\\\\",\\\\\\\"plan_id\\\\\\\":832,\\\\\\\"quantity\\\\\\\":0,\\\\\\\"low_amt\\\\\\\":100.00,\\\\\\\"insure_day_unit\\\\\\\":\\\\\\\"月\\\\\\\",\\\\\\\"is_can_sale\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"push_time\\\\\\\":1529478655000,\\\\\\\"plan_name\\\\\\\":\\\\\\\"畅邮天下A计划\\\\\\\"}\\\",\\\"BZNR\\\":[{\\\"item_name\\\":\\\"意外伤害责任\\\",\\\"item_id\\\":931,\\\"item_amt\\\":50000.0,\\\"plan_id\\\":832},{\\\"item_name\\\":\\\"公共交通意外伤害责任\\\",\\\"item_id\\\":932,\\\"item_amt\\\":100000.0,\\\"plan_id\\\":832},{\\\"item_name\\\":\\\"航空意外伤害责任\\\",\\\"item_id\\\":933,\\\"item_amt\\\":500000.0,\\\"plan_id\\\":832},{\\\"item_name\\\":\\\"意外伤害医疗责任\\\",\\\"item_id\\\":934,\\\"item_amt\\\":5000.0,\\\"plan_id\\\":832}]},{\\\"LPZY\\\":\\\"\\\",\\\"plan\\\":\\\"{\\\\\\\"guide\\\\\\\":\\\\\\\"\\\\\\\",\\\\\\\"begin_sale_date\\\\\\\":\\\\\\\"20180516\\\\\\\",\\\\\\\"insure_day\\\\\\\":\\\\\\\"12\\\\\\\",\\\\\\\"company_id\\\\\\\":11,\\\\\\\"product_id\\\\\\\":333,\\\\\\\"state\\\\\\\":\\\\\\\"0\\\\\\\",\\\\\\\"insert_time\\\\\\\":1528533314000,\\\\\\\"sale_count\\\\\\\":0,\\\\\\\"category_id\\\\\\\":\\\\\\\"14\\\\\\\",\\\\\\\"premium_amt\\\\\\\":100.0,\\\\\\\"insure_amt\\\\\\\":200000.0,\\\\\\\"plan_code\\\\\\\":\\\\\\\"151202\\\\\\\",\\\\\\\"plan_id\\\\\\\":833,\\\\\\\"quantity\\\\\\\":0,\\\\\\\"low_amt\\\\\\\":100.00,\\\\\\\"insure_day_unit\\\\\\\":\\\\\\\"月\\\\\\\",\\\\\\\"is_can_sale\\\\\\\":\\\\\\\"1\\\\\\\",\\\\\\\"push_time\\\\\\\":1529478655000,\\\\\\\"plan_name\\\\\\\":\\\\\\\"畅邮天下B计划\\\\\\\"}\\\",\\\"BZNR\\\":[{\\\"item_name\\\":\\\"意外伤害责任\\\",\\\"item_id\\\":935,\\\"item_amt\\\":100000.0,\\\"plan_id\\\":833},{\\\"item_name\\\":\\\"自驾车意外伤害责任\\\",\\\"item_id\\\":936,\\\"item_amt\\\":100000.0,\\\"plan_id\\\":833}]}]</p>\",\"channelCode\":\"web\",\"sourceType\":3,\"createdBy\":\"Sync\",\"createdTime\":1531375431000,\"modifiedBy\":null,\"modifiedTime\":null,\"field1\":null,\"field2\":null,\"field3\":null,\"field4\":null,\"descTitle\":\"保障内容\",\"descSort\":null,\"salesArea\":null,\"createdTimeStr\":\"2018-07-12\",\"modifiedTimeStr\":\"\"},{\"id\":7388,\"catalogId\":\"1\",\"isEnable\":1,\"spuId\":201704,\"description\":\"<p>web4</p>\",\"channelCode\":\"app\",\"sourceType\":3,\"createdBy\":\"Sync\",\"createdTime\":1531375431000,\"modifiedBy\":null,\"modifiedTime\":null,\"field1\":null,\"field2\":null,\"field3\":null,\"field4\":null,\"descTitle\":\"投保须知\",\"descSort\":null,\"salesArea\":null,\"createdTimeStr\":\"2018-07-12\",\"modifiedTimeStr\":\"\"},{\"id\":7389,\"catalogId\":\"1\",\"isEnable\":1,\"spuId\":201704,\"description\":\"<p>web5</p>\",\"channelCode\":\"app\",\"sourceType\":3,\"createdBy\":\"Sync\",\"createdTime\":1531375431000,\"modifiedBy\":null,\"modifiedTime\":null,\"field1\":null,\"field2\":null,\"field3\":null,\"field4\":null,\"descTitle\":\"免责声明\",\"descSort\":null,\"salesArea\":null,\"createdTimeStr\":\"2018-07-12\",\"modifiedTimeStr\":\"\"}],\"xiaoshoutujin\":[],\"spu\":[{\"id\":202260,\"spuId\":201704,\"catalogId\":\"1\",\"spuName\":\"畅“邮”天下66666\",\"spuSummary\":\"”天下66666\",\"keyWords\":\"”天下66666\",\"spuCoverPicUrl\":\"/kf-opa/news/1.jpg\",\"spuUrl\":null,\"classficationId\":\"JYXXC0019\",\"classficationName\":\"交通综合意外险\",\"isProdSync\":1,\"prodPccCode\":\"JYXXC0019\",\"prodPccName\":\"交通综合意外险\",\"shopId\":\"1\",\"shopName\":\"简易险\",\"shopUrl\":null,\"prodSysId\":\"JYXX\",\"prodSysSpuId\":\"333\",\"prodSpuName\":\"畅“邮”天下\",\"poolSpuId\":201682,\"prodSpuGroupId\":null,\"prodSpuGroupName\":null,\"supplierTypeCode\":\"Insurance\",\"supplierTypeName\":\"保险公司\",\"supplierId\":\"1\",\"supplierName\":\"中邮保险\",\"brandId\":11,\"brandName\":\"中邮保险\",\"isMultiPrice\":0,\"priceSource\":2,\"priceSourceProdSys\":\"JYXX\",\"minPrice\":10000,\"maxPrice\":null,\"priceRangeId\":null,\"priceRangeText\":null,\"spuStatus\":\"grounding\",\"approveStatus\":1,\"isOnShelf\":1,\"isDisable\":0,\"isEnable\":1,\"isDelete\":0,\"isReal\":2,\"isCartAble\":0,\"isAreaLimit\":0,\"isSaleTimeLimit\":null,\"saleStartTime\":null,\"saleEndTime\":null,\"isAutoSubmitApprove\":null,\"isAutoApprove\":null,\"prodIsAutoShelves\":null,\"isAutoShelves\":null,\"autoOnlineTime\":null,\"isAutoOffShelf\":null,\"autoOffShelfTime\":null,\"isSellAble\":1,\"submitter\":\"123542\",\"auditerId\":\"221\",\"auditTime\":1531375431000,\"onlineTime\":1531375431000,\"offlineTime\":null,\"clearingType\":null,\"erpClass\":null,\"postageTemplate\":null,\"zxptCreateGoodsType\":null,\"goodsDispatchType\":null,\"inventoryDeductionType\":null,\"createdBy\":\"Sync\",\"createdTime\":1531375431000,\"modifiedBy\":null,\"modifiedTime\":null,\"field1\":null,\"field2\":null,\"field3\":null,\"field4\":null,\"field5\":null,\"field6\":null,\"field7\":null,\"field8\":null,\"clickCount\":null,\"salesVolume\":null,\"reviewCount\":null,\"spuRating\":null,\"popularityScore\":null,\"clickCountUpdateTime\":null,\"salesVolumeUpdateTime\":null,\"reviewCountUpdateTime\":null,\"spuRatingUpdateTime\":null,\"popularityScoreUpdateTime\":null,\"spuCoverPicUrlAll\":null,\"saleStartTimeStr\":\"\",\"saleEndTimeStr\":\"\",\"autoOnlineTimeStr\":\"\",\"autoOffShelfTimeStr\":\"\",\"auditTimeStr\":\"2018-07-12\",\"onlineTimeStr\":\"2018-07-12\",\"offlineTimeStr\":\"\",\"createdTimeStr\":\"2018-07-12\",\"modifiedTimeStr\":\"\"}],\"meitiziyuan\":[{\"id\":7740,\"spuId\":201704,\"catalogId\":\"1\",\"isEnable\":1,\"mediaType\":1,\"mediaDesc\":null,\"mediaUrl\":\"/kf-opa/news/1.jpg\",\"thumbnailUrl\":\"http://192.168.202.4/kf-opa/news/1.jpg\",\"mediaOrder\":0,\"sourceType\":3,\"createdBy\":\"Sync\",\"createdTime\":1531375431000,\"modifiedBy\":null,\"modifiedTime\":null,\"field1\":null,\"field2\":null,\"field3\":null,\"field4\":null,\"mediaAllUrl\":null,\"thumbnailAllUrl\":null,\"createdTimeStr\":\"2018-07-12\",\"modifiedTimeStr\":\"\"}],\"shuxing\":null,\"xiaoshouquyu\":[],\"guigezhi\":[[{\"id\":7312,\"catalogId\":\"1\",\"isEnable\":1,\"isCommon\":null,\"isDelete\":0,\"spuId\":201704,\"skuId\":202446,\"specId\":\"JYXX0001\",\"specName\":\"方案\",\"specValueId\":\"JYXX832\",\"specValue\":\"畅邮天下A计划\",\"specType\":null,\"specCode\":\"plan_id\",\"specValueCode\":\"832\",\"createdBy\":\"Sync\",\"createdTime\":1531375432000,\"modifiedBy\":null,\"modifiedTime\":null,\"field1\":null,\"field2\":null,\"field3\":null,\"field4\":null,\"createdTimeStr\":\"2018-07-12\",\"modifiedTimeStr\":\"\"},{\"id\":7313,\"catalogId\":\"1\",\"isEnable\":1,\"isCommon\":null,\"isDelete\":0,\"spuId\":201704,\"skuId\":202447,\"specId\":\"JYXX0001\",\"specName\":\"方案\",\"specValueId\":\"JYXX833\",\"specValue\":\"畅邮天下B计划\",\"specType\":null,\"specCode\":\"plan_id\",\"specValueCode\":\"833\",\"createdBy\":\"Sync\",\"createdTime\":1531375432000,\"modifiedBy\":null,\"modifiedTime\":null,\"field1\":null,\"field2\":null,\"field3\":null,\"field4\":null,\"createdTimeStr\":\"2018-07-12\",\"modifiedTimeStr\":\"\"}]],\"placata\":{\"id\":252,\"direId\":\"2\",\"spuId\":201704,\"spuName\":\"畅“邮”天下66666\",\"cateId\":\"PXXXXYZ091\",\"cateName\":\"ceshi0910\",\"createdBy\":\"123542\",\"createdTime\":1530862983000,\"modifiedBy\":null,\"modifiedTime\":null,\"isDelete\":0,\"field1\":\"PXXX,品类88,PXXXXYZ,099,PXXXXYZ091,ceshi0910\",\"field2\":null,\"field3\":null,\"field4\":null,\"list\":null,\"createdTimeStr\":\"2018-07-06\",\"modifiedTimeStr\":\"\"},\"xiaoliang\":[],\"priceParm\":[]},\"retMessage\":\"查询成功\"}\r\n" + 
				"";
		System.out.println(JsonResult.parse(json).read("data.guigezhi[0]").toString());
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public String toResponse() {
		JSONObject object = toJsonObject();
		if (object == null) {
			object = new JSONObject();
		}
		if (!object.has("data")) {
			object.put("data", new JSONArray());
		}
		object.put("count", this.count);
		object.put("msg", "");
		object.put("code", 0);
		return object.toString();
	}

	public JsonResult setCount(int count) {
		this.count = count;
		return this;
	}
	
	public int getSelectCount() {
		return this.count;
	}

	public boolean getAssertResult() {
		return assertResult;
	}
	
}
